import { createSlice } from "@reduxjs/toolkit";
// 2.配置 createSlice 获取RTK-slice：获取到slice.actions和slice.reducer
export const grandSlice = createSlice({
  //2.1 action.type的前缀
  name: "grand",
  //2.2 初始化的切片数据
  initialState: {
    currentPage: 1,
    pageSize: 10,
    listInf: [
      {
        key: "1", //这个是必备的键值对，循环要用
        grandName: "娃哈哈",
        varietyCount: 97,
      },
      {
        key: "2",
        grandName: "白象",
        varietyCount: 98,
      },
      {
        key: "3",
        grandName: "旺仔",
        varietyCount: 99,
      },
    ],
  },
  //2.3 对应该切片数据的 reducer(操作方法)
  reducers: {
    setName(state, action) {
      state.name = action.payload;
    },
    setAge(state, action) {
      state.age = action.payload;
    },
  },
});
//2.4 stuSlice.actions：对外暴露action构造器的方法
export const { setName, setAge } = grandSlice.actions;
/* 
    2.4.1 setName(), setAge()这两个可以获取到对应操作的action
    2.4.2 setName(params)，params配置action.payload
    2.4.3 action.type=name+setName(RTK-reducer functionName)
        注意：stuSlice.actions得到的setName 和 reducers.setName两个方法同名但作用不一样
*/
